package com.stockz.equity.util;

public class MathUtil {

	public static double max(double[] values){
		return max(values,0,values.length);
	}
	
	
	public static double max(double[] values,int start, int end){
		double max = Double.MIN_VALUE;
		if(values != null && values.length != 0 && start >=0 && end >=start && end <= values.length){
			for(int i = start; i < end; i++){
				if(max < values[i]){
					max = values[i];
				}
			}
		}else{
			max = 0;
		}
		return max;
	}
	
	public static double min(double[] values){
		return min(values,0,values.length);
	}
	
	public static double min(double[] values,int start, int end){
		double min = Double.MAX_VALUE;
		if(values != null && values.length != 0 && start >=0 && end >=start && end <= values.length){
			for(int i = start; i < end; i++){
				if(min > values[i] && values[i] != 0){
					min = values[i];
				}
			}
		}else{
			min = 0;
		}
		return min;
	}
}
